package cn.iocoder.yudao.module.handguard.dal.mysql.product;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.handguard.dal.dataobject.product.ProductDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.handguard.controller.admin.product.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 产品管理 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ProductMapper extends BaseMapperX<ProductDO> {

    default PageResult<ProductDO> selectPage(ProductPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProductDO>()
                .likeIfPresent(ProductDO::getProductName, reqVO.getProductName())
                .eqIfPresent(ProductDO::getIconStr, reqVO.getIconStr())
                .eqIfPresent(ProductDO::getMaxAmount, reqVO.getMaxAmount())
                .eqIfPresent(ProductDO::getAnnualInterest, reqVO.getAnnualInterest())
                .betweenIfPresent(ProductDO::getLoanTime, reqVO.getLoanTime())
                .eqIfPresent(ProductDO::getProductType, reqVO.getProductType())
                .eqIfPresent(ProductDO::getProductLable, reqVO.getProductLable())
                .eqIfPresent(ProductDO::getProductIntroduce, reqVO.getProductIntroduce())
                .eqIfPresent(ProductDO::getProductImg, reqVO.getProductImg())
                .eqIfPresent(ProductDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(ProductDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ProductDO::getId));
    }

    default List<ProductDO> selectList(ProductExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ProductDO>()
                .likeIfPresent(ProductDO::getProductName, reqVO.getProductName())
                .eqIfPresent(ProductDO::getIconStr, reqVO.getIconStr())
                .eqIfPresent(ProductDO::getMaxAmount, reqVO.getMaxAmount())
                .eqIfPresent(ProductDO::getAnnualInterest, reqVO.getAnnualInterest())
                .betweenIfPresent(ProductDO::getLoanTime, reqVO.getLoanTime())
                .eqIfPresent(ProductDO::getProductType, reqVO.getProductType())
                .eqIfPresent(ProductDO::getProductLable, reqVO.getProductLable())
                .eqIfPresent(ProductDO::getProductIntroduce, reqVO.getProductIntroduce())
                .eqIfPresent(ProductDO::getProductImg, reqVO.getProductImg())
                .eqIfPresent(ProductDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(ProductDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ProductDO::getId));
    }

    List<ProductDO> selectListTopFive();

    ProductDO selectProductById(@Param("id") Long id);
}
